﻿
//var strCCNum;

var strCCDesc; //用户描述
var GetMsgHeight; //消息列表的高度
var g_last_time_send = 0;//上次发送消息的时间
var reSendMsg = new Array(2); //reSendMsg[0]表示上次消息、reSendMsg[1]表示下次消息。
var reSendMsgCount = 0; //重复信息的次数， -1默认不重复
var bBtnSendMsg = true; //是否第一此调用btnsendMsg（发送信息）事件，默认值是第一次调用。
var g_away_msg = "(You had been away,Please refresh!)";
var g_away_flag = false;//离开标志
var childnodes = new Array();
//读XML文件，此文件是表情符的配置文件
$.ajax({  
	url: '../static/Emo.xml',  
	type: 'GET',  
	dataType: 'xml',  
	timeout: 5000,  //设定超时  
	cache: true,   //启用缓存  
	error: function(xml) {  
		alert("Load xml file error!");  
	},  
	success: getEmoCommplete   //设置成功后回调函数  
}); 
function getEmoCommplete(xml){
    $(xml).find("Emo").each(function(i) {     //查找所有emo节点并遍历
		childnodes[i] = new Array(2);   
		childnodes[i][0] = $(this).children("EmoSign").text();
		childnodes[i][1] =$(this).children("EmoPic").text();
    });	
}
function isIE() { //ie?  
    if (!!window.ActiveXObject || "ActiveXObject" in window)  
        return true;  
    else  
        return false;  
}  
/*
*函数名：winLoad
*作用：初始化客户端
*/
function winLoad(iFlag) 
{ 
      //strCCNum = document.getElementById("strCCNum").value;
	if(g_ctype == "0"){
		$("#btn_addcustomer").hide();
	}else{
		$("#btn_addcustomer").show();
	} 
    strCCDesc = document.getElementById("strCCDesc").value;	 
	GetMsgHeight = document.getElementById("GetMsg").height;  //原始消息列表的高度
     
    var editor = document.getElementById("txtSendMsg").contentWindow;
    
    //把iframe立刻变成编辑器。
    editor.document.designMode = "On";
    editor.document.contentEditable = true;

    //但是IE与FireFox有点不同，为了兼容FireFox，所以必须创建一个新的document。
    editor.document.open();
    editor.document.writeln("<html><body></body></html>");
    editor.document.close();
    editor.document.onkeydown = shortcutKey;
    Cancel(); //调用js.js文件的Cancel事件,初始化字体设置对话框   
  //  AutoWindowSize(750,500);
    GetBusinessCard();
	displayCard(iFlag);
}
  
/*
*函数名：displayCard
*作用：显示或隐藏服务名片
*参数：flag ---显示或隐藏标记。0显示，其它值隐藏。
*/
 function displayCard(flag)
 {
    if (flag == 0)
    {
		$('#Card').show();
		$('#Cardimg').show();
	//   AutoWindowSize(750,510);
	}
	 else
	 {
		$('#Card').hide();
		$('#Cardimg').hide();		 
	   //	AutoWindowSize(500,510);
	 }
  }
  
/*
*函数名：GetBusinessCard
*作用：获取服务名片
*/
function GetBusinessCard()
{
   document.getElementById("CardName").innerHTML = strCCDesc;
   var strBusinessCard =  document.getElementById("strBusinessCard").value; 
   
   document.getElementById("CardContent").innerHTML = strBusinessCard.replace(/\|/g,"<br/>");   
}


/*
*函数名：AutoWindowSize
*作用：调整IE窗口大小
*参数：x -------宽度
*参数：y -------高度
*/
function AutoWindowSize(x,y)
{
	var width = x;     
	var height = y;  

	width = eval(width); 
	height = eval(height); 
	if (width <x) 
	width = x; 
	else if (width > screen.width) 
	width = screen.width; 
	 
	if (height < y) 
	height = y; 
	else if (height > screen.height) 
	height = screen.height; 	 
	window.resizeTo(width,height);
}

/*
*函数名：btnSendMsg
*作用：发送消息
*参数：txtSendMsg ---消息内容
*/
function btnSendMsg(url,peer_sid,sid)
{ 	
	var editor = document.getElementById("txtSendMsg").contentWindow; 
	var txtSendMsg =  editor.document.getElementsByTagName("body")[0].innerHTML;
	if(window.navigator.appName == "Microsoft Internet Explorer")
	  {//客户端是IE浏览器
		 if(txtSendMsg == null || txtSendMsg == "")
	     {		
		   return;
	     }
	  }
	  else
	  {//客户端是MozillaFirefox 、Opera或其它浏览器
	     if(txtSendMsg.length == 1 || txtSendMsg.length == 0)		   
	      {		
			 return;
	      }
	  }	   
	if(g_last_time_send == 0){
		g_last_time_send = new Date().getTime();
	}else{
		if(new Date().getTime() - g_last_time_send < 1000){
			g_last_time_send = new Date().getTime();
			 alert("抱歉,请说话慢些！");
			 return;			
		}
	}
	g_last_time_send = new Date().getTime();
	//同一消息连续发送不能超过5次
	if(bBtnSendMsg != true)
	{
	  reSendMsg[0] = reSendMsg[1];	  
	}
	else
	{
	   bBtnSendMsg = false;
	}
	reSendMsg[1] = txtSendMsg;	

	if(reSendMsg[0] == txtSendMsg)
	{
	   reSendMsgCount ++
	   if(reSendMsgCount >= 5)
	   {
		 alert("同一消息连续发送不能超过5次！");
		 return;
	   }	   
	}
//预先处理保存需要发送给bridge的的信息
 	var strSend_IM_Msg = txtSendMsg; 
  	strSend_IM_Msg = strSend_IM_Msg.replace(/\<P>/g,"");
	strSend_IM_Msg = strSend_IM_Msg.replace(/\<\/P>/g,"");
	strSend_IM_Msg = strSend_IM_Msg.replace(/\<BR>/g,"\r\n");
    strSend_IM_Msg = strSend_IM_Msg.replace(/\<br>/g,"\r\n");
	strSend_IM_Msg = strSend_IM_Msg.replace(/\&nbsp;/g," ");
	strSend_IM_Msg = SendEmo(strSend_IM_Msg);  //把发送的表情符图片，转换成表情符。
		
  //	strSend_IM_Msg = utf16to8(strSend_IM_Msg);
	if(strSend_IM_Msg.length >1000)
	{
		alert("消息长度发送不能超过1000字节！");
		 return;
	}
	
	//strSend_IM_Msg = base64encode(strSend_IM_Msg);	
		//通过XMLHttp发送到服务器	
	var paraObj ={};
	paraObj.act = "sendmsg";
	paraObj.sid = sid;
	paraObj.peer_sid = peer_sid;
	paraObj.msg = strSend_IM_Msg;

	//var sendMsg = JSON.stringify(paraObj);
	sendCmd(url,paraObj,true,null);
	
	//处理发送自己的消息
	if (EditEmoticons(txtSendMsg) != txtSendMsg)
	{
		 txtSendMsg = EditEmoticons(txtSendMsg);
	}
	
	if(CommentCmoticons(txtSendMsg) != txtSendMsg)
	{
		 txtSendMsg =  CommentCmoticons(txtSendMsg);
	}
	//过滤一些HTML标签格式符  
	txtSendMsg = txtSendMsg.replace(/\<P>/g,"");
	txtSendMsg = txtSendMsg.replace(/\<\/P>/g,"<BR>");
	
	//增加消息记录    
    var myGetFontType = new GetFontType();
	txtSendMsg = "<span style = 'font-family:" + myGetFontType.sFontFamily + ";font-style:"+ myGetFontType.sFontStyle +";font-weight:"+ myGetFontType.sFontWeight +";font-size:"+ myGetFontType.sFontSize +";text-Decoration:"+myGetFontType.sTextDecoration+"; '>"+ txtSendMsg +"</span>"
	document.getElementById("GetMsg").contentWindow.document.getElementById("txtGetMsg").innerHTML += "<span style = 'color: #457535'>我说:("+ Time() +")</span><br>"+ txtSendMsg + "<br>"; 
	
	editor.document.getElementsByTagName("body")[0].innerHTML = "";	
	txtSendMsg = SendEmo(txtSendMsg);  //把发送的表情符图片，转换成表情符。	
	
	//过滤一些HTML标签格式符     
	txtSendMsg = txtSendMsg.replace(/\<BR>/g,"\r\n");
	txtSendMsg = txtSendMsg.replace(/\&nbsp;/g," ");
//再获得信息
	ScrollPane();  //定位消息记录滚动条的位置	

}
var URLDisp;//取得IM消息URL
function GetHttpReq()
{
	var httpReq;
	if( isIE() )
	{//客户端是IE浏览器
	     try
		 {
		   httpReq = new ActiveXObject("Microsoft.XMLHTTP");
			if (httpReq.overrideMimeType){
			   httpReq.overrideMimeType('text/xml');
			  } 
		   
		 }
		 catch(e)
		 {		      
			httpReq = new ActiveXObject("Msxml2.XMLHTTP");
		 }
	 }
	 else
	 {//客户端是MozillaFirefox 、Opera或其它浏览器
		 httpReq = new XMLHttpRequest();
	 }
	 return httpReq;
}


//取得消息函数
//
/*
function GetMsg()
{
	 var xmlReadMsg = GetHttpReq();
         xmlReadMsg.open('GET',   URLDisp,   true);  

	 //消息显示回调函数
       xmlReadMsg.onreadystatechange = function readMsgHandler(){
	   if (xmlReadMsg.readyState == 4)
       {
	      if(xmlReadMsg.status   ==   200 )   
		  {
          	  var strfullMsg = utf8to16(base64decode(xmlReadMsg.responseText));
	          var iPart = strfullMsg.indexOf(":");
		  	  var strName = strfullMsg.substring(0,iPart);
		  	  var strMsg = strfullMsg.substring(iPart + 1,strfullMsg.length);			  
			  if(strMsg.indexOf(g_away_msg) >= 0)
			  {
			  		g_away_flag = true;
			  }
		      WriteGetMsg(strMsg,strName);	
		  }// if(xmlReadMsg.status   ==   200 || xmlReadMsg.status ==0)   
	   	}//if (xmlReadMsg.readyState == 4)
	};
	if(!g_away_flag)
	{	 	
      //禁止IE缓存
 	    xmlReadMsg.setRequestHeader("If-Modified-Since","0"); 
        //发送数据
		xmlReadMsg.send(null);
        setTimeout('GetMsg()',4000); 
	}
}
*/
//定时刷新界面
function RefreshMsg(strUrl,sid) {
//	if(g_msg) return;
	$.ajax({ 
		type: "post", 
		url: strUrl, 
		dataType: "json", 
		timeout:25000,
		async:true,
		data: {"act": "getmsg","sid": sid },
		success: function (data,textStatus) { 
			if(data != null )
			{
				WriteGetMsg(data.Msg, data.Name);	
			}			
			setTimeout(function () { 
			RefreshMsg( g_get_url,g_sid );	
			}, 500);							
		}, 
		 complete:function(XMLHttpRequest,textStatus){  
					if(XMLHttpRequest.readyState=="4"){  
						//alert(XMLHttpRequest.responseText);  
					}  
			},  		
		error: function (XMLHttpRequest, textStatus, errorThrown) { 
				setTimeout(function () { 
				RefreshMsg( g_get_url,g_sid );	
				}, 1000);	
			if (textStatus == "timeout") { // 请求超时
					  // 递归调用
				// 其他错误，如网络错误等
				} else { 
				}
		} 
	});
}
//strLen 长度 
//bUpperChar 是否大写字母 
//bLowerChar 是否小写字母 
//bDigital 是否数字 
function rnd_str(strLen,bUpperChar,bLowerChar,bDigital) 
{ 
	var Seed_array=new Array(); 
	var seedary; 
	var i; 
	
	Seed_array[0]="" 
	Seed_array[1]= "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"; 
	Seed_array[2]= "a b c d e f g h i j k l m n o p q r s t u v w x y z"; 
	Seed_array[3]= "0 1 2 3 4 5 6 7 8 9"; 
	
	
	if (!bUpperChar&&!bLowerChar&&!bDigital){bUpperChar=true;bLowerChar=true;bDigital=true;} 
	
	if (bUpperChar){Seed_array[0]+=   Seed_array[1];} 
	if (bLowerChar){Seed_array[0]+=" "+Seed_array[2];} 
	if (bDigital){Seed_array[0]  +=" "+Seed_array[3];} 
	
	Seed_array[0]= Seed_array[0].split(" "); 
	seedary="" 
	for (i=0;i<strLen;i++) 
	{ 
		seedary+=Seed_array[0][Math.round(Math.random( )*(Seed_array[0].length-1))] 
	} 
	return(seedary); 
} 

/*
*函数名：WriteGetMsg
*作用：写入接收消息
*参数：strMsgContent ----消息内容
*参数：userName -------用户名
*/
function WriteGetMsg(strMsgContent,userName)
 {  
   var EmotionsPicture;   
   var TemptxtMsg;
   
    //判断用户是否在线
     /*
     *写判断用户是否在线代码处
     */
	if(userName =="" && strMsgContent != ""){
		strMsgContent="我已离开,稍后联系";
	}
	if (EditEmoticons(strMsgContent) != strMsgContent)
	{
		 strMsgContent = EditEmoticons(strMsgContent);//判断是否有以()开头和结尾表情符，如果有，把表情符转换成相应的图片	
	}
	
	if(CommentCmoticons(strMsgContent) != strMsgContent)
	{
		 strMsgContent =  CommentCmoticons(strMsgContent);//判断是否有其它表情符，如果有，把表情符转换成相应的图片
	}	
  
     if(strMsgContent != null && strMsgContent.length >0 ) 
	 {  //接收的的消息不为空，把消息增加到记录中
		
		document.getElementById("GetMsg").contentWindow.document.getElementById("txtGetMsg").innerHTML += "<span style ='color: #1F338F\'>"+ userName +"("+Time()+")</span>"+"<br>" + strMsgContent +"<br>" ;	
		ScrollPane();
		if(!document.hasFocus() || window.screenTop < 0)
		{
			window.focus();
		}
	 }	// if(strMsgContent != 0) 
}
	
/*
*函数名：Time
*作用：获取系统时间
*返回值：HH：MM：SS格式的系统时间
*/
function Time() 
{
	var d, s ,Hour,Min,Sec;          
	d = new Date();
	var vHour = d.getHours();
	var vMin = d.getMinutes();
	var vSec = d.getSeconds();
	if (vHour<10)
	{
		Hour="0"+vHour;
	}
	else
	{
		Hour=vHour;      
	}
	if (vMin<10)
	{
		Min="0"+vMin;
	}
	else
	{
		Min=vMin;
	}
	if (vSec<10)
	{
		Sec="0"+vSec;
	}
	else
	{
		Sec=vSec;
	}
	s=Hour+":"+Min+":"+Sec;   
	return s;
}

/*
*函数名：SetShortcutKey
*作用：自定义发生消息的快捷键
*参数：flag ---显示或隐藏标记。0显示，其它值隐藏。
*/
function SetShortcutKey(flag)
{
	if(flag == 0)
	{
		document.getElementById("ShortcutKeyDiv").style.display = "";
	}
	else
	{
		document.getElementById("ShortcutKeyDiv").style.display = "none";
	}
	
	var sKeyValue = GetShortcutKeyValue();
	if(sKeyValue.toLowerCase() == "enter")
	{
		document.getElementById("ibtnMsg").alt = "回车键发送";
	}
	else
	{
	   document.getElementById("ibtnMsg").alt = "Ctrl+回车键发送";
	}	
}

/*
*函数名：GetShortcutKeyValue
*作用：获取当前快捷键的值
*/
function GetShortcutKeyValue()
{
	var obj=document.getElementsByName("RadioGroup1");
    for(var i=0;i<obj.length;i++)
	{
       if(obj[i].checked)
	   {
         var sKeyValue = obj[i].value;
       }
    }
	
	return sKeyValue;
}

/*
*函数名：shortcutKey
*作用：触发定义发生消息的快捷键
*说明：在IE下有效,firefox.opera无效。待解决
*/
function shortcutKey(evt) 
{    
	var peer_id = document.getElementById("peer_id").value;	 
	var strSid = document.getElementById("strSID").value;	 
    var editor = document.getElementById("txtSendMsg").contentWindow;    
    
	var sKeyValue = GetShortcutKeyValue();
	if( isIE() )
    {//客户端是IE浏览器
		
        if(sKeyValue.toLowerCase() == "enter")
		{//当前快捷键为Enter
			if(editor.event.keyCode == 13) 
			{
				btnSendMsg(g_send_url,peer_id,strSid);	 
			}
		}
		else
		{//当前快捷键为Ctrl+Enter
			if(editor.event.ctrlKey && editor.event.keyCode == 13) 
			{
				btnSendMsg(g_send_url,peer_id,strSid);		 
			}
		}
    	
	    //隐藏的快捷键为Alt+S
		if(editor.event.altKey && editor.event.keyCode == 83) 
	    {
			btnSendMsg(g_send_url,peer_id,strSid);		 
	    }
    }
    else
    {//客户端是MozillaFirefox 、Opera或其它浏览器
		if(sKeyValue.toLowerCase() == "enter"){
			if(evt.keyCode == 13 && !evt.ctrlKey){
				btnSendMsg(g_send_url,peer_id,strSid);
			}
		}else{
			if( evt.ctrlKey && evt.keyCode == 13) 
			{
				btnSendMsg(g_send_url,peer_id,strSid);	
			}
			
			if(evt.altKey && evt.keyCode == 83) 
			{
				btnSendMsg(g_send_url,peer_id,strSid);	         
			}
		}
    }

} 

/*
*函数名：ScrollPane
*作用：定位接收消息ifrom的滚动条的位置
*/
function ScrollPane() 
{
	var obj = document.getElementById("GetMsg").contentWindow.document.body;
	obj.scrollTop = obj.scrollHeight;	
} 

	
/*
*函数名：EditEmoticons
*作用：取出消息中类似(*)的表情符号的字符表达式
*参数：txtMsg --------消息内容
*返回值：TemptxtMsg -----解析表情符号后的消息内容
*/
function EditEmoticons(txtMsg)
{  
	var Emo ;  //嫌疑表情符
	var iRow = 0;  
	var TemptxtMsg = txtMsg;   //获取的消息
	var Star = txtMsg.indexOf("(");
	var End = txtMsg.indexOf(")");
	var EmoPicture ;   //表情符图片
	
	while (Star != -1 && End != -1)
	 {
		if(Star != -1)
		{
			Emo = txtMsg.substring(Star,End+1);	
				  
			EmoPicture = GetReturnEmo(Emo);   //读XML，判断是否为表情符号。	   
		   
			if (EmoPicture != "")  //如果是表情符号，获取对应的图片。
			{
				EmoPicture = "<img src = 'images/moticons/" + EmoPicture + "'>";
				TemptxtMsg = TemptxtMsg.replace(Emo ,EmoPicture)		   
			}
			
			txtMsg = txtMsg.substr(End+1);
		}
		
		Star = txtMsg.indexOf("(");
		End = txtMsg.indexOf(")");
		iRow ++;    
	 } 
	return TemptxtMsg;	
}


/*
*函数名：CommentCmoticons
*作用：通过正则式解析表情符号
*参数：txtMsg --------消息内容
*返回值：TemptxtMsg ----解析表情符号后的消息内容
*/
function CommentCmoticons (txtMsg)  //
{
	txtMsg =  txtMsg.replace(/\&lt;/g,"<");
	txtMsg =  txtMsg.replace(/\&gt;/g,">");
	var re = /:-#|:->|8-P|:<>|8-\)|8\*\/|\*-\)|\+o\(|\|-\)|:-#|:->|:-o|:\*|:S|:!|:\||:'\(|:\$|:@|;\)|:D|:\)|:\|/g;
	var TemptxtMsg =  txtMsg;   
	var Emo = TemptxtMsg.match(re);    
	var EmoPicture ; 
	if (Emo != null)
	{ 
		for ( var i = 0 ;i<Emo.length ; i++)
		{		
			EmoPicture = GetReturnEmo(Emo[i].toString()); //读XML，判断是否为表情符号。
		
			if (EmoPicture != "")  //如果是表情符号，获取对应的图片。
			{
				EmoPicture = "<img src = 'images/moticons/" + EmoPicture + "'>";
				TemptxtMsg = TemptxtMsg.replace(Emo[i].toString() ,EmoPicture)					   	   
			}	
			
		}
	}      
	return TemptxtMsg;
}
	
/*
*函数名：GetReturnEmo
*作用：获取表情符号对应的表情图片
*参数：Emo ----------表情符号
*返回值：EmoticonsPicture ----返回相应的表情图片
*/
function GetReturnEmo(Emo)  
{	
	var EmoticonsPicture = "";

	for (var i=0 ;i<childnodes.length ; i++)
	{	
	   if (childnodes[i][0] == Emo)
		{
			EmoticonsPicture  = childnodes[i][1];
			break;
		}
	}

	return EmoticonsPicture;
}	
	
/*
*函数名：GetReturnEmo
*作用：获取表情图片对应的表情符号
*参数：Emo ----------表情图片
*返回值：EmoticonsPicture ----返回相应的表情符号
*/
function GetRetrurnEmoSign(Emo)
{
    var EmoticonsSign ="";

	for (var i=0 ;i<childnodes.length ; i++)
	{	
	   if (childnodes[i][1] == Emo)
		{
			EmoticonsSign  = childnodes[i][0];
		}
	}

	return EmoticonsSign;
}

/*
*函数名：DisplayEmo
*作用：显示或隐藏服务表情层
*参数：flag ---显示或隐藏标记。0显示，其它值隐藏。
*/
function DisplayEmo(flag) 
{
   if(flag == 0)
   {
       document.getElementById("EmoList_div").style.display = "";
   }
   else
   {
      document.getElementById("EmoList_div").style.display = "none";
   }
}

/*
*函数名：DisplayFile
*作用：显示或隐藏发送文件层
*参数：flag ---显示或隐藏标记。0显示，其它值隐藏。
*/
function DisplayFile(flag) 
{
   if(flag == 0)
   {
       document.getElementById("File_Div").style.display = "";
	  
		var ChangeGetMsgHeight = document.getElementById("GetMsg").height;
		if(ChangeGetMsgHeight == GetMsgHeight)
		{
		   var FileDivHeight = document.getElementById("File_Div").clientHeight;
		   document.getElementById("GetMsg").height  = ChangeGetMsgHeight - FileDivHeight;
		}
	  
   }
   else
   {
      document.getElementById("File_Div").style.display = "none";
	  document.getElementById("GetMsg").height = GetMsgHeight;	  
   }
}
/*
*函数名：selectEmo
*作用：选择表情符
*/ 
function selectEmo(ImgSrc)
{
	
	document.getElementById("EmoList_div").style.display = "none";	
	document.getElementById("txtSendMsg").contentWindow.document.getElementsByTagName("body")[0].innerHTML += "<img src = '" + ImgSrc + "'>" ;	
	document.getElementById("txtSendMsg").contentWindow.document.body.focus();
}

/*
*函数名：SendEmo
*作用：发送消息时,解析表情。即把发送的表情符图片转换成相应的表情符
*参数：txtSendMsg ----------消息内容
*返回值：EmoticonsPicture ----解析表情符号后的消息内容
*/
function SendEmo(txtSendMsg) 
{
	var SendMsg;
	var TemptxtSendMsg = txtSendMsg;
	var Star = txtSendMsg.indexOf("<");
	var End = txtSendMsg.indexOf(">"); 
	
	if (Star != -1 && End != -1)
	{	
		while (Star !=-1 && End != -1)
		{ 
			SendMsg = TemptxtSendMsg.substring(Star,End+1);
			TemptxtSendMsg = TemptxtSendMsg.substr(End+1);
			Star = TemptxtSendMsg.indexOf("<");		
			End = TemptxtSendMsg.indexOf(">"); 
			
			var EmoPic = SendMsg.split ("/");
			for (var i = 0;i<EmoPic.length;i++)
			{
				var EndGif = EmoPic[i].toString().indexOf(".gif");
				if (EndGif != -1)
				{
					var Emo = EmoPic[i].substr(0,EndGif+4);					
					var Emosign = GetRetrurnEmoSign(Emo);   //读XML，返回表情字符.
					if (Emosign != "")
					{  
						txtSendMsg = txtSendMsg.replace(SendMsg ,Emosign)		               
					}
				
				}
			} 
			
		}
	
	}		  
	return txtSendMsg;
}

 
/*
*函数名：txtSendMsgFont
*作用：发送消息框字体设置
*参数：object ---document.getElementById('txtSendMsg')即发送消息框
*/ 
 function txtSendMsgFont(object)
 {    
    var myGetFontType = new GetFontType();
    object.style.fontFamily = myGetFontType.sFontFamily;
    object.style.fontSize = myGetFontType.sFontSize; 
    object.style.fontWeight = myGetFontType.sFontWeight;
    object.style.fontStyle = myGetFontType.sFontStyle;
    object.style.textDecoration  = myGetFontType.sTextDecoration;
   
 }
 
/*
*函数名：GetFontType
*作用：设置字体
*返回值：FontType ---Object类型,字体设置属性
*/
 function GetFontType()
 {
    var chkThroughObj = document.getElementById("chkThrough");
    var chkUnderlineObj = document.getElementById("chkUnderline");    
    var sFontStyle = document.getElementById("txtFontStyle").value;
    
    var FontType = new Object;
    FontType.sFontSize = document.getElementById("txtFontSize").value;
    FontType.sFontFamily = document.getElementById("txtFontFamily").value;
    
    //初始化字体设置
    FontType.sFontWeight = "normal";
    FontType.sFontStyle = "normal";
    FontType.sTextDecoration = "none";
	
    if (sFontStyle == "粗体")
    {
       FontType.sFontWeight = "bold";
    }
    else if(sFontStyle == "斜体")
    {
       FontType.sFontStyle = "italic";
    }
    else if(sFontStyle == "粗斜体")
    {
         FontType.sFontWeight = "bold";
         FontType.sFontStyle = "italic";
    }
	
    if(chkThroughObj.checked == true)
    {
        FontType.sTextDecoration = "line-through" ;
    }
  
    if(chkUnderlineObj.checked == true)
    {
        FontType.sTextDecoration = "underline" ;
    }
   
    if(chkThroughObj.checked == true  && chkUnderlineObj.checked == true)
    {
        FontType.sTextDecoration = "underline line-through" ;
    }
    
    return FontType;
 }
 
/*
*函数名：btnSave
*作用：保存消息记录
*说明：只有IE6或以上版本才可以保存消息记录
*/
  function btnSave()
  {
     if(isIE())
	 {//客户端是IE浏览器
	    
		//判断IE的版本号，只有IE6或以上版本才可以保存消息记录
		var sVersion = window.navigator.appVersion;
		var version = new Array();
		var IEver;
		version = sVersion.split(";");
		var iVerLenght = version.length;
		for (var i=0 ;i<iVerLenght;i++)
		{
		   if(version[i].toString().indexOf("MSIE") > 0)
		     {
		        IEver = version[i].toString();
		        break;
		     }
		}		
	      var MsgContent = document.getElementById("GetMsg").contentWindow.document.getElementById("txtGetMsg").innerHTML;
	      document.open("text/html", "_blank");
	      document.write(MsgContent);
	      document.execCommand("SaveAs",false,"消息记录");
	      document.close();
	      history.back();		
		/*	
		if(parseFloat(IEver.substring(5)) >= 6)
		{//IE6或以上版本

		}
		else
		{//IE6以下版本
		   alert("保存失败!检查出您的IE浏览器版本太低，请使用IE6或以上版本。");
		}*/
	 }
	 else
	 {//客户端是MozillaFirefox 、Opera或其它浏览器
	    alert("检查出您的浏览器不是IE，请使用IE6或以上版本的浏览器。");
	 }
  }  
  
function exitMsg(send_url, sid, peer_sid  )
{
	var paraObj ={};
	paraObj.act = "remove";
	paraObj.sid = sid;
	paraObj.peer_sid = peer_sid;
	sendCmd(send_url,paraObj,false,null);	
}

function sendCmd(strUrl,sentData,bAsync,resultCallback)
{
	var nResult = -99;
	$.ajax({ 
		type: "post", 
		url: strUrl, 
		dataType: "json", 
		data: sentData,
		async:bAsync,
		success: function (data,textStatus) { 
			nResult = data.result;
			if(resultCallback!="" && resultCallback != null)
				resultCallback(nResult);
			return nResult;
		}, 
		 complete:function(XMLHttpRequest,textStatus){  
					if(XMLHttpRequest.readyState=="4"){  
						//alert(XMLHttpRequest.responseText);  
					}  
			},  		
		error: function (XMLHttpRequest, textStatus, errorThrown) { 
			alert("对方不在线或网络错误!");
			if (textStatus == "timeout") { // 请求超时
					//getEvent(); // 递归调用
				// 其他错误，如网络错误等
				} else { 
					//getEvent();
				}
		} 
	});	
	return nResult;
}

function getScreen(ctype,peer_sid,sid){
	var strUploadUrl = window.location.host+ '/upload/';
	var paraObj={};
	paraObj.up_url = strUploadUrl;
	paraObj.peer_sid = peer_sid;
	paraObj.sid = sid;
	paraObj.ctype = ctype;
	sendCmdCallback('cutscreen',paraObj,null);
}

function sendCmdCallback(cmd_name,paraObj,resultCallback)
{
	var nResult = -99;
	var bSync = false;
	$.ajax({ 
		type: "post", 
		url: "http://127.0.0.1:31839/cmd/", 
		dataType: "jsonp", 
		data: {"act": cmd_name,"para":JSON.stringify(paraObj)},
		timeout:1000,
		success: function (data,textStatus) { 
			// $("#StatusArea").append("--- " + data );
			bSync = true;
			nResult = data.result;
			if(resultCallback!="" && resultCallback != null)
				resultCallback(nResult);
			return nResult;
		}, 
		 complete:function(XMLHttpRequest,textStatus){  
					if(XMLHttpRequest.readyState=="4"){  
						//alert(XMLHttpRequest.responseText);  
					}  
			},  		
		error: function (XMLHttpRequest, textStatus, errorThrown) { 
			//alert("网络错误! " + textStatus + ", error: " + errorThrown );
			alert("没有安装截图服务!");
			if (textStatus == "timeout") { // 请求超时
					//getEvent(); // 递归调用
				// 其他错误，如网络错误等
				} else { 
					//getEvent();
				}
			bSync = true;
		} 
	});	
	return nResult;
}

function btnAddCustomer(strUrl,sid,peer_id ){
	$.post(strUrl, {"act":"customer_add","sid":sid,"peer_id":peer_id},
	   function(data){
		 if(data.r == 0)
		 {
			// openTab('客户管理',data.url);
		}
		 else if(data.r == 1)
		 {
			 
		 } 
	   }, "json");		

}
